package com.mojo.collection.map;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * LinkedHashMap源码解析示例
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/12/13 10:28
 */
public class LinkedHashMapDemo {
    public static void main(String[] args) {
        Map<Integer, Object> map = new LinkedHashMap<>();
        map.put(3, "asd");
        map.put(1, "asd");
        map.put(2, "asd");
        map.put(4, "asd");
        map.put(5, "asd");
        // {1=sdfa5, 2=sdfa2, 3=sdfa3, 4=sdfa4}
        //  使用双向列表将每个Entry串起来，所以linkedHashMap是有序的，这里有序是指元素的迭代顺序跟插入顺序一致
        for (Map.Entry<Integer, Object> entry : map.entrySet()) {
            System.out.print(entry.getKey()+" ");
            System.out.println(entry.getValue());
        }
        System.out.println("=============================================");
        System.out.println(map);
        Map<Integer, Object> integerObjectMap = Collections.synchronizedMap(map);
    }
}
